import store from 'store';

import router from '@/router';

router.beforeEach((to, from, next) => {
    // 获取token
    let token = store.get("sa-token");
    // 判断是否已登陆
    if (token && token.isLogin) {
        if (to.path == "/login") {
            next({path: "/homepage"});
        } else {
            next();
        }
    } else if (to.meta.requireAuth) {
        next({path: "/login", query: {redirect: to.fullPath}});
    } else {
        next();
    }
});

router.afterEach(() => {
    // TODO 更新面包屑等内容
});